package stream;

import pojo.Student;

import java.util.stream.Stream;

public class StreamReduce {
    public static void main(String[] args) {
        Integer sum = Stream.of(2, 3, 4, 5).reduce(100, (a, b) -> {
            System.out.println(a+"----"+b);
            return a + b;
        });
        System.out.println("sum = " + sum);
        //求所有人的年龄总和
        Student stu1=new Student("101","汪云飞",22);
        Student stu2=new Student("102","周雨晴",20);
        Student stu3=new Student("103","大头",25);

        Integer sum2 = Stream.of(stu1, stu2, stu3)
                .map(x -> x.getAge())
                //拆箱 装箱
                .reduce(0, (x, y) -> x + y);
        System.out.println(sum2);
    }
}
